import Vue from 'vue'
import VueResource from 'vue-resource'
Vue.use(VueResource)

const DataRoot = "/data/"
export default ({
  getTraingCategoryList: function () {
    if (!this.CategoryList) {
      this._getData(DataRoot + 'trainingCategory.json', this.CategoryList)
    }
    return this.CategoryList
  },
  getFunctions: function (callback) {
    if (!this.functions) {
      this._getData(DataRoot + 'functions.json', this.functions,callback)
    }
    else{
      callback(this.functions)
    }
  },
  getOrganizations:function(callback){
    if(!this.organizations){
      this._getData(DataRoot + 'organizations.json', this.organizations,callback)
    }
    else{
      callback(this.organizations)
    }
  },
  getRoles: function () {
    if (!this.roles) {
      this._getData(DataRoot + 'roles.json', this.roles)
    }
    return this.roles
  },
  getUsers:function(callback){
      this._getData(DataRoot + 'users.json', this.users,callback)
  },
  getReports:function(callback){
    if (!this.reports) {
      this._getData(DataRoot + 'reports.json', this.reports,callback)
    }
    else{
      callback(this.reports)
    }
  },
  _getData: function (url, container,callback) {
    Vue.http.get(url).then((response) => {
      container = response.data
      callback(response.data)
    }, (response) => {
      console.log(response)
    })
  }
})